package com.example.demo02.controller;

import com.example.demo02.entity.Students;
import com.example.demo02.service.StudentsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

/**
 * <p>
 * 学生表 前端控制器
 * </p>
 *
 * @author wuyunbin
 * @since 2023-03-27
 */
@RestController
@RequestMapping("students")
@Slf4j
public class StudentsController {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @GetMapping("add")
    public void add(){
        Random rand=new Random();
        for (int i = 0; i < 1000000; i++) {
            Students stu=new Students();
            String str=rand.nextInt(100000)+"";
            stu.setName(str);
            rabbitTemplate.convertAndSend("add",stu);
            log.info("新增数据:{}",str);
        }
    }
}
